<?php
$repo = urldecode($_POST['dir']);
$filtro = $_POST['filtro'];
if(file_exists($repo)) {
	$files = scandir($repo);
	natcasesort($files);
	if(count($files) > 2) { /* The 2 accounts for . and .. */
		echo "<ul class='jqueryFileTree' style='display: none;'>";
		// All dirs
		foreach( $files as $file ) {
			if( file_exists($repo . $file) && $file != '.' && $file != '..' && is_dir($repo . $file) ) {
				if ($filtro) {
					if (utf8_encode($file) == $_POST['filtro']) {
					$dire = utf8_encode($repo.$file);
					$directorio = substr($dire,13)."/";
					echo "<li class=\"directory collapsed\"><a href=\"#\" class=\"patch\" rel=\"" .
					htmlentities($repo . $file) . "/\">" .
					htmlentities($file) . "</a></li>";
					}
				} else {
					$dire = utf8_encode($repo.$file);
					$directorio = substr($dire,13)."/";
					echo "<li class=\"directory collapsed\"><a href=\"#\" class=\"patch\" rel=\"" .
					htmlentities($repo . $file) . "/\">" .
					htmlentities($file) . "</a></li>";
				}


			}
		}
		// All files
		echo "</ul>";
	}
}
?>
